package com.sunplus.system.registration.controller;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.sunplus.system.registration.domain.PortalDictionaries;
import com.sunplus.system.registration.service.IPortalDictionariesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sunplus.common.annotation.Log;
import com.sunplus.common.core.controller.BaseController;
import com.sunplus.common.core.domain.AjaxResult;
import com.sunplus.common.enums.BusinessType;
import com.sunplus.common.utils.poi.ExcelUtil;

/**
 * 字典码Controller
 * 
 * @author sunplus
 * @date 2021-03-25
 */
@RestController
@RequestMapping("/registration/dictionariesMgr")
public class PortalDictionariesController extends BaseController
{
    @Autowired
    private IPortalDictionariesService portalDictionariesService;

    /**
     * 查询字典码列表
     */
    @PreAuthorize("@ss.hasPermi('system:dictionaries:list')")
    @GetMapping("/listPain")
    public AjaxResult list(PortalDictionaries portalDictionaries)
    {
        startPage();
        List<PortalDictionaries> list = portalDictionariesService.findListBySupCode(portalDictionaries);
        JSONObject data = getDataTable(list);
        data.put("ButtonRight", "add,edit,del,view,SetRole,updatepassword");
        return AjaxResult.success(data);
    }


    /**
     * 导出字典码列表
     */
    @PreAuthorize("@ss.hasPermi('system:dictionaries:export')")
    @Log(title = "字典码", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PortalDictionaries portalDictionaries)
    {
        List<PortalDictionaries> list = portalDictionariesService.findListBySupCode(portalDictionaries);
        ExcelUtil<PortalDictionaries> util = new ExcelUtil<PortalDictionaries>(PortalDictionaries.class);
        return util.exportExcel(list, "dictionaries");
    }

    /**
     * 获取字典码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dictionaries:query')")
    @GetMapping(value = "/{pid}")
    public AjaxResult getInfo(@PathVariable("pid") String pid)
    {
        return AjaxResult.success(portalDictionariesService.selectPortalDictionariesById(pid));
    }

    /**
     * 新增字典码
     */
    @PreAuthorize("@ss.hasPermi('system:dictionaries:add')")
    @Log(title = "字典码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PortalDictionaries portalDictionaries)
    {
        return toAjax(portalDictionariesService.insertPortalDictionaries(portalDictionaries));
    }

    /**
     * 修改字典码
     */
    @PreAuthorize("@ss.hasPermi('system:dictionaries:edit')")
    @Log(title = "字典码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PortalDictionaries portalDictionaries)
    {
        return toAjax(portalDictionariesService.updatePortalDictionaries(portalDictionaries));
    }

    /**
     * 删除字典码
     */
    @PreAuthorize("@ss.hasPermi('system:dictionaries:remove')")
    @Log(title = "字典码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pids}")
    public AjaxResult remove(@PathVariable String[] pids)
    {
        return toAjax(portalDictionariesService.deletePortalDictionariesByIds(pids));
    }
}
